package com.it.task;

import com.it.config.MQConfig;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MyAsync {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void asyncAddOrder() {
        //异步下订单
        Map<String, Object> param = new HashMap<>();

        param.put("username", "zhangsan");
        param.put("order", "10001");

        rabbitTemplate.convertAndSend(MQConfig.myOneExchange, MQConfig.myOneRouting, param, new MessagePostProcessor() {
            @Override
            public Message postProcessMessage(Message message) throws AmqpException {
                message.getMessageProperties().setExpiration("10000");
                return message;
            }
        });
        System.out.println("发送数据完毕");


    }
}
